package AdmissionController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.renjun.smweb.commons.global.StaticCaches;
import com.renjun.smweb.commons.util.Encrypt;
import com.renjun.smweb.dao.pojo.LoginInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.renjun.smweb.controller.AdmissionController.AdmissionController;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by huamin on 2017/2/23.
 * 录取管理M7
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:/spring-mvc.xml", "classpath*:/spring-mybatis.xml"})
public class AdmissionControllerTestCase {

    @Autowired
    private AdmissionController admissionController;
    //模拟request,response
    private MockHttpServletRequest request;
    private MockHttpServletResponse response;

    @Before
    public void setUp() throws Exception {
        request = new MockHttpServletRequest();
        StaticCaches.setRealRootPath("D:\\svn\\yeyzsxj\\target\\yeyzsxj-1.0");
        System.out.println(StaticCaches.getRealRootPath());
//        request.getSession().setAttribute("userinfo", getxtLoginfo());
//        request.getSession().setAttribute("userinfo", getqxLoginfo());
        request.getSession().setAttribute("userinfo", getxxLoginfo());
//        response = new MockHttpServletResponse();
    }

    //获取缓存LoginInfo系统管理员
    private LoginInfo getxtLoginfo() {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId("hmxt");
        loginInfo.setRoleid("0");
        loginInfo.setRoletype("0");
        loginInfo.setUsername("测试系统管理员");
        loginInfo.setRealname("junit测试系统管理员");
        return loginInfo;
    }

    //获取缓存LoginInfo教育局管理员
    private LoginInfo getjyjLoginfo() {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId("hmjyj");
        loginInfo.setRoleid("1");
        loginInfo.setRoletype("1");
        loginInfo.setUsername("测试教育局管理员");
        loginInfo.setRealname("junit测试教育局管理员");
        return loginInfo;
    }

    //获取缓存LoginInfo区县管理员
    private LoginInfo getqxLoginfo() {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId("hmqx");
        loginInfo.setRoleid("2");
        loginInfo.setRoletype("2");
        loginInfo.setDistrictcode("310116");
        loginInfo.setUsername("测试区县管理员");
        loginInfo.setRealname("junit测试区县管理员");
        return loginInfo;
    }

    //获取缓存LoginInfo学校管理员
    private LoginInfo getxxLoginfo() {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId("hmxx");
        loginInfo.setRoleid("3");
        loginInfo.setRoletype("3");
        loginInfo.setDistrictcode("310116");
        loginInfo.setSchoolcode("3101160001");
        loginInfo.setUsername("测试学校管理员");
        loginInfo.setRealname("junit测试学校管理员");
        return loginInfo;
    }

    /**
     * 报名学生录取列表M7-11
     *
     * @param {limit:10,offset:0,order:"",sort:"",xm,sfzjh,sfzlx,njdm,ryyj,hksf,hkqx,djlx,lqzt,checkstatus,hksfscope,hkqxscope}
     * @return [{id,bmxxmc,njdm,xm,xb,sfzlx,sfzjh,csrq,hksf,hkqx,ryyj,zfxz,djlx,lqzt,checkstatus}]
     * by huamin
     */
    @Test
    public void testQueryXXDJXSList(){
        System.out.println("报名学生录取列表M7-11");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("limit",10);
        params.put("offset",0);
        params.put("order","");
        params.put("sort","");
        params.put("xm","");
        params.put("sfzjh","");
        params.put("sfzlx","");
        params.put("njdm","");
        params.put("ryyj","");
        params.put("hksf","");
        params.put("hkqx","");
        params.put("djlx","");
        params.put("lqzt","");
        params.put("checkstatus","1");
        params.put("hksfscope","1");
        params.put("hkqxscope","1");
//        params.put("hkqxscope","0");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.queryXXDJXSList(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 导出登记学生录取列表M7-112
     *
     * @param {limit:10,offset:0,order:"",sort:"",xm,sfzjh,sfzlx,njdm,ryyj,hksf,hkqx,djlx,lqzt,checkstatus,hksfscope,hkqxscope}
     * @return [{id,bmxxmc,njdm,xm,xb,sfzlx,sfzjh,csrq,hksf,hkqx,ryyj,zfxz,djlx,lqzt,checkstatus}]
     * by huamin
     */
    @Test
    public void testExpQueryXXDJXSList(){
        System.out.println("导出报名学生录取列表M7-112");
        //封装参数
        Map<String,Object> params=new HashMap<>();
//        params.put("id","1,2");
        params.put("limit",10);
        params.put("offset",0);
        params.put("order","");
        params.put("sort","");
        params.put("xm","");
        params.put("sfzjh","");
        params.put("sfzlx","");
        params.put("njdm","");
        params.put("ryyj","");
        params.put("hksf","");
        params.put("hkqx","");
        params.put("djlx","");
        params.put("lqzt","");
        params.put("checkstatus","1");
        params.put("hksfscope","1");
        params.put("hkqxscope","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.expQueryXXDJXSList(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 录取学生名单列表M7-12
     *
     * @param {limit:10,offset:0,order:"",sort:"",xm,sfzjh,sfzlx,njdm,ryyj,hksf,hkqx,djlx,lqzt,checkstatus,hksfscope,hkqxscope}
     * @return [{id,lqxxmc,njdm,xm,xb,sfzlx,sfzjh,csrq,hksf,hkqx,ryyj,zfxz,djlx,lqzt,checkstatus}]
     * by huamin
     */
    @Test
    public void testQueryXXLuquList(){
        System.out.println("录取学生名单列表M7-12");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("limit",10);
        params.put("offset",0);
        params.put("order","");
        params.put("sort","");
        params.put("xm","测试");
        params.put("sfzjh","");
        params.put("sfzlx","");
        params.put("njdm","");
        params.put("ryyj","");
        params.put("hksf","310000");
        params.put("hkqx","310115");
        params.put("djlx","");
        params.put("lqzt","");
        params.put("checkstatus","1");
        params.put("hksfscope","1");
        params.put("hkqxscope","1");
//        params.put("hkqxscope","0");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.queryXXLuquList(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 导出录取学生名单列表M7-122
     *
     * @param {limit:10,offset:0,order:"",sort:"",xm,sfzjh,sfzlx,njdm,ryyj,hksf,hkqx,djlx,lqzt,lqzt,checkstatus,hksfscope,hkqxscope}
     * @return [{id,lqxxmc,njdm,xm,xb,sfzlx,sfzjh,csrq,hksf,hkqx,ryyj,zfxz,djlx,lqzt,checkstatus}]
     * by huamin
     */
    @Test
    public void testExpQueryXXLuquList(){
        System.out.println("导出录取学生名单列表M7-122");
        //封装参数
        Map<String,Object> params=new HashMap<>();
//        params.put("id","1,2");
        params.put("limit",10);
        params.put("offset",0);
        params.put("order","");
        params.put("sort","");
        params.put("xm","测试");
        params.put("sfzjh","");
        params.put("sfzlx","");
        params.put("njdm","");
        params.put("ryyj","");
        params.put("hksf","310000");
        params.put("hkqx","310115");
        params.put("djlx","");
        params.put("lqzt","");
        params.put("checkstatus","1");
        params.put("hksfscope","1");
        params.put("hkqxscope","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.expQueryXXLuquList(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }


    /**
     * 区县录取学生名单列表M7-13
     *
     * @param {limit:10,offset:0,order:"",sort:"",xm,sfzjh,sfzlx,njdm,ryyj,hksf,hkqx,djlx,lqzt,checkstatus,hksfscope,hkqxscope}
     * @return [{id,djxxmc,lqxxmc,njdm,xm,xb,sfzlx,sfzjh,csrq,hksf,hkqx,ryyj,zfxz,djlx,lqzt,checkstatus}]
     * by huamin
     */
    @Test
    public void testQueryQXLuquList(){
        System.out.println("区县录取学生名单列表M7-13");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("limit",10);
        params.put("offset",0);
        params.put("order","");
        params.put("sort","");
        params.put("xm","测试");
        params.put("sfzjh","");
        params.put("sfzlx","");
        params.put("njdm","");
        params.put("ryyj","");
        params.put("hksf","310000");
        params.put("hkqx","310115");
        params.put("djlx","");
        params.put("lqzt","");
        params.put("checkstatus","1");
        params.put("hksfscope","1");
//        params.put("hkqxscope","1");
        params.put("hkqxscope","0");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.queryQXLuquList(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }
    /**
     * 导出区县录取学生名单列表M7-132
     *
     * @param {limit:10,offset:0,order:"",sort:"",xm,sfzjh,sfzlx,njdm,ryyj,hksf,hkqx,djlx,lqzt,checkstatus,hksfscope,hkqxscope}
     * @return [{id,djxxmc,lqxxmc,njdm,xm,xb,sfzlx,sfzjh,csrq,hksf,hkqx,ryyj,zfxz,djlx,lqzt,checkstatus}]
     * by huamin
     */
    @Test
    public void testExpQueryQXLuquList(){
        System.out.println("导出区县录取学生名单列表M7-132");
        //封装参数
        Map<String,Object> params=new HashMap<>();
//        params.put("id","1,2");
        params.put("limit",10);
        params.put("offset",0);
        params.put("order","");
        params.put("sort","");
        params.put("xm","测试");
        params.put("sfzjh","");
        params.put("sfzlx","");
        params.put("njdm","");
        params.put("ryyj","");
        params.put("hksf","310000");
        params.put("hkqx","310115");
        params.put("djlx","");
        params.put("lqzt","");
        params.put("checkstatus","1");
        params.put("hksfscope","1");
        params.put("hkqxscope","1");
//        params.put("hkqxscope","0");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.expQueryQXLuquList(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 录取-查看录取信息M7-20
     *
     * @param {id}
     * @return [djinfo:{ id,xm,xb,sfzlx,sfzjh,djxx,djsj,djlx,lqxx,lqzt,djxxmc,lqxxmc,lqsj},bminfo:[{bmxx},{bmsj}]]
     * by huamin
     */
    @Test
    public void testQueryluquListById(){
        System.out.println("录取-查看录取信息M7-20");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.queryluquListById(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 统筹录取学校列表M7-251
     * @param {id}
     * @return{lqxx,lqxxmc}
     *  by huamin
     */
    @Test
    public void testGetTongchouLuquSchoolList(){
        System.out.println("区县录取学生名单列表M7-13");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.getTongchouLuquSchoolList(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }
    /**
     * 录取M7-21
     * @param {id}
     * @return{}
     *  by huamin
     */
    @Test
    public void testSetLuquById(){
        System.out.println("录取M7-21");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //录取M7-21
        JSONObject rs = admissionController.setLuquById(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 取消录取M7-22
     * @param {id}
     * @return{}
     *  by huamin
     */
    @Test
    public void testCancelLuquById(){
        System.out.println("取消录取M7-22");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //取消录取M7-22
        JSONObject rs = admissionController.cancelLuquById(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 设置待统筹M7-23
     * @param {id}
     * @return{}
     *  by huamin
     */
    @Test
    public void testSetDaitongchouById(){
        System.out.println("设置待统筹M7-23");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //设置待统筹M7-23
        JSONObject rs = admissionController.setDaitongchouById(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 取消待统筹M7-24
     * @param {id}
     * @return{}
     *  by huamin
     */
    @Test
    public void testCancelDaitongchouById(){
        System.out.println("取消待统筹M7-24");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //取消待统筹M7-24
        JSONObject rs = admissionController.cancelDaitongchouById(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 设置统筹录取M7-25
     * @param {id,lqxx}
     * @return{}
     *  by huamin
     */
    @Test
    public void TestSetTongchouLuquById(){
        System.out.println("设置统筹录取M7-25");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        params.put("lqxx","3101160004");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //设置统筹录取M7-25
        JSONObject rs = admissionController.setTongchouLuquById(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 取消统筹录取M7-26
     * @param {id}
     * @return{}
     *  by huamin
     */
    @Test
    public void testCancelTongchouLuquById(){
        System.out.println("取消统筹录取M7-26");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //取消统筹录取M7-26
        JSONObject rs = admissionController.cancelTongchouLuquById(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 生成待统筹学生上报表M7-4
     *
     * @param {}
     * @return []
     * by huamin
     */
    @Test
    public void testExpDaiTongchouSbReport(){
        System.out.println("生成待统筹学生上报表M7-4");
        //封装参数
        Map<String,Object> params=new HashMap<>();
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = admissionController.expDaiTongchouSbReport(request, response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    /**
     * 生成单个录取通知书M7-51
     *
     * @param {id}
     * @return []
     * by huamin
     */
    @Test
    public void testExpluquNoticeById() {
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("id","1");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //生成单个录取通知书M7-51
        JSONObject rs = admissionController.expluquNoticeById(request, response);
        String jiem = Encrypt.jiem((String) rs.get("response"));
        System.out.println("json : " + jiem);
    }

    /**
     * 生成全部录取通知书M7-52
     *
     * @param {}
     * @return []
     * by huamin
     */
    @Test
    public void testExpluquNoticeAll() {
        //封装参数
        Map<String,Object> params=new HashMap<>();
        params.put("order","");
        params.put("sort","");
        params.put("xm","测试");
        params.put("sfzjh","");
        params.put("sfzlx","");
        params.put("njdm","");
        params.put("ryyj","");
        params.put("hksf","310000");
        params.put("hkqx","310115");
        params.put("djlx","");
        params.put("lqzt","");
        params.put("checkstatus","1");
        params.put("hksfscope","1");
        params.put("hkqxscope","1");
//        params.put("hkqxscope","0");
        //map转json字符串
        request.setContent(JSONObject.toJSONString(params).getBytes());
        //生成全部录取通知书M7-52
        JSONObject rs = admissionController.expluquNoticeAll(request, response);
        String jiem = Encrypt.jiem((String) rs.get("response"));
        System.out.println("json : " + jiem);
    }
}
